#include <Python.h>
#include <iostream>

#include "EShellWx.h"

using namespace end1;

DECLARE_APP(EShellWx)
IMPLEMENT_APP_NO_MAIN(EShellWx)

static PyObject *
end_glue_system(PyObject *self, PyObject *args)
{
    const char *command;
    int sts;

    if (!PyArg_ParseTuple(args, "s", &command))
        return NULL;
    sts = system(command);
    return Py_BuildValue("i", sts);
}

static PyObject *
test(PyObject *self, PyObject *args)
{
    int a, b, c;
    
    PyArg_ParseTuple(args, "iii", &a, &b, &c);
    std::cout << "cpp test" << a << b << c << std::endl;
    std::cout << "test from pok5" << std::endl;
	
    wxApp* pApp = new EShellWx(); 
    wxApp::SetInstance(pApp);
	
	//int argc = 0;
	//wxChar** argv = NULL;
	//wxEntry(argc, argv);

	int argc = 1;
    wxChar* argv []= {"this"};
    wxEntry(argc, argv);
	//wxEntryStart(argc, argv);
	//wxTheApp->CallOnInit();

    return Py_None;
}

static PyMethodDef SpamMethods[] = {
    {"system",  end_glue_system, METH_VARARGS,
     "Execute a shell command."},
    {"test",  test, METH_VARARGS,
     "edit passed tuple."},
    {NULL, NULL, 0, NULL}        /* Sentinel */
};

PyMODINIT_FUNC
initend_glue(void)
{
    (void) Py_InitModule("end_glue", SpamMethods);
}

int
main(int argc, char *argv[])
{
    /* Pass argv[0] to the Python interpreter */
    Py_SetProgramName(argv[0]);

    /* Initialize the Python interpreter.  Required. */
    Py_Initialize();

    /* Add a static module */
    initend_glue();
}


